import Cookies from 'js-cookie'
let pointX=0;
let pointY=0;
let w=window.screen.width;
let h=window.screen.height;
let m=w/2;
export class DraggableModal {

    static startDrag(dialog,mouseEvent) {
      console.log("事件",mouseEvent);
      console.log("初始化dialog",dialog);
      
      let dragContext = {
        dialog,
        startX:0, //mouseEvent.clientX
        startY: 0, //mouseEvent.clientY
        dragging: false,
      };

      // if(Cookies.get(pointX)!=""){
      //   console.log("Cookies还原值...");
      //   dragContext.startX=Cookies.get(pointX);
      //   dragContext.startY=Cookies.get(pointY);
      // }

      console.log("屏幕宽度:",w,"高度:",h,"中间值",m);


    //   console.log("pointX是否大于0",pointX);
      const handleMouseMove = (event) => {
        if (dragContext.dragging) {
          const style = document.defaultView.getComputedStyle(dialog.$el);
          const width= parseFloat(style.width) || 0;
          const heigh=parseFloat(style.height) || 0;
          const left = parseFloat(style.left) || 0;
          const top = parseFloat(style.top) || 0;
          console.log("鼠标事件",event);
          console.log("当前元素坐标:",event.clientX,event.clientY);


          //console.log("dialog.$el.style",dialog.$el.style);
          //console.log("dialog.$el.style.left",dialog.$el.style.left);
            // if(event.clientX>m){ //右
            //   dialog.$el.style.left = event.clientX+100  + 'px';
            // }else{ //左
            //   dialog.$el.style.left = event.clientX-1000  + 'px';  
            // }
            //dialog.$el.style.top = event.clientY-100  + 'px';
            if(event.clientX>m){ //右
              dialog.$el.style.left = event.clientX-left/3-width/2+280+"px";
            }else{ //左
               dialog.$el.style.left = event.clientX-left/3-width/2-280+"px";
            }
            dialog.$el.style.top = event.clientY+top/3-180+"px";
        }

      };
   
      const handleMouseUp = (mouseEvent) => {
          document.removeEventListener('mousemove', handleMouseMove);
          document.removeEventListener('mouseup', handleMouseUp);
          dragContext.dragging = false;
      };
   
      dragContext.dragging = true;
      document.addEventListener('mousemove', handleMouseMove);
      document.addEventListener('mouseup', handleMouseUp);
    }
  }